package com.cmccgz.udacs_landlord_webapp.main.housemanager.function;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;

import com.cmccgz.baselibrary.base.BaseActivity;
import com.cmccgz.udacs_landlord_webapp.R;
import com.cmccgz.udacs_landlord_webapp.data.Injection;
import com.cmccgz.udacs_landlord_webapp.main.housemanager.list.HouseListActivity;


/**
 * @author: Huang
 * @Descripion:
 * @date 2017/6/6 11:29
 */

public class HouseFunctionActivity extends BaseActivity {

    public static final String HOUSE_NAME = "house_name";
    public static final String HOUSE_ID = "house_id";
    public static final String BUILDING_NAME = "building_name";
    public static final String BUILDING_ID = "building_id";

    private int type;
    private String name;
    private String id;

    @Override
    protected int setLayoutId() {
        return 0;
    }

    @Override
    protected void initView() {
        initData();
    }

    private void initData() {
        Intent intent = getIntent();
        type = intent.getIntExtra(HouseListActivity.TYPE, HouseListActivity.TYPE_NULL);
        name = intent.getStringExtra(HouseListActivity.HOUSE_NAME);
        id = intent.getStringExtra(HouseListActivity.HOUSE_ID);
    }

    @Override
    protected void initFragment() {
        Fragment fragment = fragmentManager.findFragmentById(R.id.contentFrame);
        if (fragment == null) {
            Bundle bundle = new Bundle();
            switch (type) {
                case HouseListActivity.TYPE_CHECKOUT://退房
                    fragment = HouseCheckOutFragment.newInstance();
                    bundle.putString(HOUSE_NAME,name);
                    bundle.putString(HOUSE_ID,id);
                    fragment.setArguments(bundle);
                    showFragment(fragment);
                    break;
                case HouseListActivity.TYPE_EXCHANGE://换房
                    fragment = HouseExchangeFragment.newInstance();
                    bundle.putString(HOUSE_NAME,name);
                    bundle.putString(HOUSE_ID,id);
                    fragment.setArguments(bundle);
                    showFragment(fragment);
                    break;
                case HouseListActivity.TYPE_ROOM_COUNT://房间统计
                    fragment = HouseRoomCountFragment.newInstance();
                    bundle.putString(BUILDING_NAME,name);
                    bundle.putString(BUILDING_ID,id);
                    fragment.setArguments(bundle);
                    showFragment(fragment);
                    break;
                default:
                    finish();
                    break;
            }
        }
        switch (type){
            case HouseListActivity.TYPE_CHECKOUT://退房
                new HouseCheckOutPresenter(Injection.provideHouseManagerRepository(),(HouseCheckOutFragment) fragment);
                break;
            case HouseListActivity.TYPE_EXCHANGE://换房
                new HouseExchangePresenter(Injection.provideHouseManagerRepository(),(HouseExchangeFragment) fragment);
                break;
            case HouseListActivity.TYPE_ROOM_COUNT://房间统计
                new HouseRoomCountPresenter(Injection.provideHouseManagerRepository(),(HouseRoomCountFragment) fragment);
                break;
            default:
                break;
        }
    }

    @Override
    protected void beforePermission() {

    }

    @Override
    protected int setSystemBarColorId() {
        return 0;
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        Fragment fragment = fragmentManager.findFragmentById(R.id.contentFrame);
        if (fragment!=null) {
            fragment.onActivityResult(requestCode, resultCode, data);
        }
    }
}
